<!-- 文件补发申请单列表页面 -->
<template>
  <div class="app-container">
        <div class="header-center" style="display: flex;">
          <router-link to="/main/biao/wjbufa" class="back-btn" style="padding-top: 23px;white-space: nowrap;">
            <i class="el-icon-arrow-left"></i> 返回
          </router-link>
          <h2 class="title" style="text-align: center;width: 100%;">文件补发申请单列表</h2>
        </div>
    <div class="filter-container">
      <el-input
        v-model="listQuery.keyword"
        placeholder="请输入申请单位/文件编号/文件名称"
        style="width: 300px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />&emsp;
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>&emsp;
      <el-button
        class="filter-item"
        style="margin-left: 10px;"
        type="success"
        icon="el-icon-plus"
        @click="handleCreate"
      >
        新增
      </el-button>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column label="申请单位" prop="applicationUnit" min-width="120" />
      <el-table-column label="申请日期" prop="applicationDate" width="120" align="center" />
      <el-table-column label="核准人" prop="approvedBy" width="100" align="center" />
      <el-table-column label="审核人" prop="reviewedBy" width="100" align="center" />
      <el-table-column label="经办人" prop="handledBy" width="100" align="center" />
      <el-table-column label="创建时间" prop="createTime" width="180" align="center" />
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-view"
            @click="handleView(row)"
          >
            查看
          </el-button>
          <el-button
            size="mini"
            type="success"
            icon="el-icon-edit"
            @click="handleUpdate(row)"
          >
            编辑
          </el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(row)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getFileReissueList, deleteFileReissue } from '@/api/fileReissue'
import Pagination from '@/components/Pagination'

export default {
  name: 'WjbufaList',
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        current: 1,
        size: 10,
        keyword: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const response = await getFileReissueList(this.listQuery)
        this.list = response.data.records
        this.total = response.data.total
      } catch (error) {
        console.error('获取列表失败:', error)
      }
      this.listLoading = false
    },
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleCreate() {
      this.$router.push('/main/biao/wjbufa')
    },
    handleView(row) {
      this.$router.push({
        path: '/main/biao/wjbufa',
        query: { id: row.id, type: 'view' }
      })
    },
    handleUpdate(row) {
      this.$router.push({
        path: '/main/biao/wjbufa',
        query: { id: row.id, type: 'edit' }
      })
    },
    handleDelete(row) {
      this.$confirm('确认删除该文件补发申请单吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          await deleteFileReissue(row.id)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        } catch (error) {
          console.error('删除失败:', error)
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container{
  width: 1200px;
  margin: 0 auto;
  height: 100vh;
}
.filter-container {
  padding-bottom: 10px;
  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }
}
</style> 